from datetime import datetime
from typing import List, Union

from fastapi import Query, UploadFile
from pydantic import BaseModel, Field

from forward.extend.pydantic.base import BaseSchema
from forward.schema_base import EmptyStrToNone
from forward.utils.tools import ToolsUtil


class CommonAlbumCateOutSchema(BaseSchema):
    """
    类目
    """

    id: int
    name: str = Field(default="")
    pid: int
    type: int
    created_time: datetime|None = Field(None)  # 创建时间
    updated_time: datetime|None = Field(None)  # 更新时间
    model_config = {
        "alias_generator": ToolsUtil.to_lower_camel,
        "populate_by_name": True,
    }


class CommonAlbumOutSchema(BaseSchema):
    """
    文件
    """

    id: int
    cid: int
    name: str = Field()
    ext: str
    size: int
    url: str | None = Field(None)
    uri: str = Field()
    created_time: datetime | None = Field(None)  # 创建时间
    updated_time: datetime | None = Field(None)  # 更新时间
    model_config = {
        "alias_generator": ToolsUtil.to_lower_camel,
        "populate_by_name": True,
    }


class CommonAlbumAddInSchema(BaseModel):
    cid: int
    aid: int
    uid: Union[int, None] = Query(default=None)
    type: int
    name: str
    ext: str
    size: int
    url: str


class CommonAlbumDelInSchema(BaseModel):
    ids: List[int]


class CommonAlbumListInSchema(BaseModel):
    type: Union[int, None, EmptyStrToNone] = Query(default=None)
    keyword: Union[str, None] = Query(default=None)
    cid: Union[int, None, EmptyStrToNone] = Query(default=None)


class CommonAlbumCateListInSchema(BaseModel):
    type: Union[int, None] = Query(default=None)
    keyword: Union[str, None] = Query(default=None)


class CommonAlbumCateDelInSchema(BaseModel):
    id: int


class CommonAlbumRenameInSchema(BaseModel):
    id: int
    name: str


class CommonAlbumMoveInSchema(BaseModel):
    ids: List[int]
    cid: int


class CommonAlbumCateEditInSchema(BaseModel):
    type: Union[int, None] = Query(default=10)
    name: Union[str, None] = Query(default="")
    pid: Union[int, None] = Query(default=None)


class CommonFileUploadInSchema(BaseModel):
    file_in: UploadFile
    cid: int
